// pages/ViewAPPlication/ViewAPPlication.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    booking_list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  
  onLoad: function (options) {
    let that=this;
    wx.cloud.callFunction({
      name:"order",
      data:{
        type:"checkMyOrder",
      },
      success(res){
        console.log(res)
        if (res.result.code==200){
          let data=res.result.data;
          let list=data;
          for (var i=0;i<data.length;i++){
            list[i].time=that.TransTime(data[i].timestamp)
            // list[i].time=new Date(data[i].timestamp).toLocaleString();
            if (data[i].state==0) 
              {
                list[i].state_text="通过";
              }else if(data[i].state==1){
                list[i].state_text="不通过";
              }else if(data[i].state==2){
                list[i].state_text="未审核";
              }else if(data[i].state==3){
                list[i].state_text="审核中";
              }else{
                list[i].state_text="发生错误"
              }  
          }
          console.log(list)
        that.setData({
          booking_list:list
        })
        }else{
          wx.showToast({
            icon:'none',
            title: res.result.msg,
          })
        }
      },
      fail(res){
        wx.showToast({
        icon:'none',
        title: '云函数调用失败',
      })
    }
    })
  },
  showQR:function(e){
    console.log(e)
    let id=e.currentTarget.dataset.id;
    let timestamp=this.data.booking_list[id].timestamp;
    console.log(timestamp)
    wx.cloud.callFunction({
      name:"QRcode",
      data:{
      type:"getQRcode",
      timestamp:timestamp,
      },
      success(res){
        console.log(res)
        
        if (res.result.code==200)
        {
          let path=res.result.data.path
           wx.navigateTo({
           url: '../showQRcode/showQRcode?path='+path,
           })
         }else{
          wx.showToast({
            title: res.result.msg,
            icon:'none',
            duration:2000
          })
        }
         
      },
      fail(){}
      })
   
  },
  TransTime:function(timestamp){
    let time=new Date(timestamp)
    let year=time.getFullYear();
    let month=time.getMonth()+1;
    let date=time.getDate();
    let hours=time.getHours();
    let result=year+'/'+month+'/'+date+' '+hours+':'+'00';
    // console.log(result)
    return result
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})